package com.yuanchu.store.controller;

import com.yuanchu.common.utils.PageResult;
import com.yuanchu.common.utils.R;
import com.yuanchu.common.validator.ValidationGroups;
import com.yuanchu.store.dto.EditGradeParamsDto;
import com.yuanchu.store.dto.UserGradeDto;
import com.yuanchu.store.entity.YoshopUserGradeEntity;
import com.yuanchu.store.service.YoshopUserGradeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @version: 1.0
 * @Author: adan
 * @description: 用户会员等级
 * @date: 2024-02-07 1:00
 */
@Api(value = "UserGradeController", tags = {"用户会员等级"})
@RestController
@RequestMapping("user/grade")
public class ShopUserGradeController {

    @Resource
    private YoshopUserGradeService userGradeService;

    /**
     * 查询会员等级
     */
    @GetMapping("/{gradeId}")
    public YoshopUserGradeEntity queryUserGrade(@PathVariable("gradeId") Integer gradeId) {
        return userGradeService.getById(gradeId);
    }

    // /user/grade/list?page=1
    @ApiOperation("查询等级列表")
    @GetMapping("/list")
    public R queryUserGradeList(){
        PageResult<UserGradeDto> userList = userGradeService.queryUserGradeList();
        return R.ok().putPage("data", userList);
    }

    @ApiOperation("修改等级")
    @PostMapping("/edit")
    public R editUserGrade(@RequestBody @Validated(ValidationGroups.Update.class) EditGradeParamsDto param){
        userGradeService.editUserGrade(param);
        return R.ok();
    }
    @ApiOperation("删除等级")
    @PostMapping("/delete")
    public R deleteUserGrade(@RequestBody @Validated(ValidationGroups.Update.class) EditGradeParamsDto param){
        userGradeService.deleteUserGrade(param.getGradeId());
        return R.ok();
    }


}
